package com.elvin.androidservice;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import android.os.Environment;



public class DiskTools {

	public static boolean saveToDisk(String fileName, byte[] data){
		boolean flag = false;
		
		File file =new File(Environment.getExternalStorageDirectory(), fileName);
		
		if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
			FileOutputStream outputStream = null;
			
			try {
				outputStream = new FileOutputStream(file);
				outputStream.write(data, 0, data.length);
				flag = true;
			} catch (Exception e) {
				// TODO: handle exception
			}finally{
				if(outputStream != null){
					try {
						outputStream.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}
		
		return flag;
		
	}
}
